#include "unp.h"

ssize_t
writen(int fd, const void *vptr, ssize_t n) {
    ssize_t     nleft;
    ssize_t     nwritten;
    const char* ptr;

    nleft   = n;
    ptr     = vptr;
    while(nleft > 0) {
        if ((nwritten = write(fd, ptr, nleft)) <= 0) {
            if (nwritten < 0 && errno == EINTR) 
                nwritten = 0;
            else
                return -1;
        }
        ptr += nwritten;
        nleft -= nwritten;
    }

    return n;
}
